<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>

<meta charset="utf-8">
<meta name="generator" content="quarto-99.9.9">

<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">


<title>Fastmath documentation – Optimization</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
ul.task-list li input[type="checkbox"] {
  width: 0.8em;
  margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */ 
  vertical-align: middle;
}
/* CSS for syntax highlighting */
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
  { counter-reset: source-line 0; }
pre.numberSource code > span
  { position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
  { content: counter(source-line);
    position: relative; left: -1em; text-align: right; vertical-align: baseline;
    border: none; display: inline-block;
    -webkit-touch-callout: none; -webkit-user-select: none;
    -khtml-user-select: none; -moz-user-select: none;
    -ms-user-select: none; user-select: none;
    padding: 0 4px; width: 4em;
  }
pre.numberSource { margin-left: 3em;  padding-left: 4px; }
div.sourceCode
  {   }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
</style>


<script src="site_libs/quarto-nav/quarto-nav.js"></script>
<script src="site_libs/quarto-nav/headroom.min.js"></script>
<script src="site_libs/clipboard/clipboard.min.js"></script>
<script src="site_libs/quarto-search/autocomplete.umd.js"></script>
<script src="site_libs/quarto-search/fuse.min.js"></script>
<script src="site_libs/quarto-search/quarto-search.js"></script>
<meta name="quarto:offset" content="./">
<link href="./transform.html" rel="next">
<link href="./interpolation.html" rel="prev">
<link href="./clay/resources/favicon.png" rel="icon" type="image/png">
<script src="site_libs/quarto-html/quarto.js"></script>
<script src="site_libs/quarto-html/popper.min.js"></script>
<script src="site_libs/quarto-html/tippy.umd.min.js"></script>
<script src="site_libs/quarto-html/anchor.min.js"></script>
<link href="site_libs/quarto-html/tippy.css" rel="stylesheet">
<link href="site_libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
<script src="site_libs/bootstrap/bootstrap.min.js"></script>
<link href="site_libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
<link href="site_libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light">
<script id="quarto-search-options" type="application/json">{
  "location": "sidebar",
  "copy-button": false,
  "collapse-after": 3,
  "panel-placement": "start",
  "type": "textbox",
  "limit": 50,
  "keyboard-shortcut": [
    "f",
    "/",
    "s"
  ],
  "show-item-context": false,
  "language": {
    "search-no-results-text": "No results",
    "search-matching-documents-text": "matching documents",
    "search-copy-link-title": "Copy link to search",
    "search-hide-matches-text": "Hide additional matches",
    "search-more-match-text": "more match in this document",
    "search-more-matches-text": "more matches in this document",
    "search-clear-button-title": "Clear",
    "search-text-placeholder": "",
    "search-detached-cancel-button-title": "Cancel",
    "search-submit-button-title": "Submit",
    "search-label": "Search"
  }
}</script>


</head>

<body class="nav-sidebar floating">

<div id="quarto-search-results"></div>
  <header id="quarto-header" class="headroom fixed-top">
  <nav class="quarto-secondary-nav">
    <div class="container-fluid d-flex">
      <button type="button" class="quarto-btn-toggle btn" data-bs-toggle="collapse" data-bs-target=".quarto-sidebar-collapse-item" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
        <i class="bi bi-layout-text-sidebar-reverse"></i>
      </button>
        <nav class="quarto-page-breadcrumbs" aria-label="breadcrumb"><ol class="breadcrumb"><li class="breadcrumb-item"><a href="./optimization.html">Optimization</a></li></ol></nav>
        <a class="flex-grow-1" role="button" data-bs-toggle="collapse" data-bs-target=".quarto-sidebar-collapse-item" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">      
        </a>
      <button type="button" class="btn quarto-search-button" aria-label="" onclick="window.quartoOpenSearch();">
        <i class="bi bi-search"></i>
      </button>
    </div>
  </nav>
</header>
<!-- content -->
<div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article">
<!-- sidebar -->
  <nav id="quarto-sidebar" class="sidebar collapse collapse-horizontal quarto-sidebar-collapse-item sidebar-navigation floating overflow-auto">
    <div class="pt-lg-2 mt-2 text-left sidebar-header">
    <div class="sidebar-title mb-0 py-0">
      <a href="./">Fastmath documentation</a> 
    </div>
      </div>
        <div class="mt-2 flex-shrink-0 align-items-center">
        <div class="sidebar-search">
        <div id="quarto-search" class="" title="Search"></div>
        </div>
        </div>
    <div class="sidebar-menu-container"> 
    <ul class="list-unstyled mt-1">
        <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="./index.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text">Preface</span></a>
  </div>
</li>
        <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="./core.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text">Core</span></a>
  </div>
</li>
        <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="./vector_matrix.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text">Vectors and matrices</span></a>
  </div>
</li>
        <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="./random.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text">Random</span></a>
  </div>
</li>
        <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="./stats.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text">Statistics</span></a>
  </div>
</li>
        <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="./polynomials.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text">Polynomials</span></a>
  </div>
</li>
        <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="./special.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text">Special functions</span></a>
  </div>
</li>
        <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="./calculus.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text">Calculus</span></a>
  </div>
</li>
        <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="./interpolation.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text">Interpolation</span></a>
  </div>
</li>
        <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="./optimization.html" class="sidebar-item-text sidebar-link active">
 <span class="menu-text">Optimization</span></a>
  </div>
</li>
        <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="./transform.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text">Transforms</span></a>
  </div>
</li>
        <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="./ml.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text">Machine Learning</span></a>
  </div>
</li>
        <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="./complex_quaternions.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text">Complex numbers and quaternions</span></a>
  </div>
</li>
        <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="./easings.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text">Easings</span></a>
  </div>
</li>
        <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="./fields.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text">Vector fields</span></a>
  </div>
</li>
        <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="./efloat.html" class="sidebar-item-text sidebar-link">
 <span class="menu-text">EFloat</span></a>
  </div>
</li>
    </ul>
    </div>
</nav>
<div id="quarto-sidebar-glass" class="quarto-sidebar-collapse-item" data-bs-toggle="collapse" data-bs-target=".quarto-sidebar-collapse-item"></div>
<!-- margin-sidebar -->
    <div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
        <nav id="TOC" role="doc-toc" class="toc-active">
    <h2 id="toc-title">Table of contents</h2>
   
  <ul>
  <li><a href="#bayesian-optimization" id="toc-bayesian-optimization" class="nav-link active" data-scroll-target="#bayesian-optimization">Bayesian optimization</a></li>
  <li><a href="#reference" id="toc-reference" class="nav-link" data-scroll-target="#reference">Reference</a>
  <ul>
  <li><a href="#fastmath.optimization" id="toc-fastmath.optimization" class="nav-link" data-scroll-target="#fastmath.optimization">fastmath.optimization</a>
  <ul>
  <li><a href="#bayesian-optimization-1" id="toc-bayesian-optimization-1" class="nav-link" data-scroll-target="#bayesian-optimization-1">bayesian-optimization</a></li>
  <li><a href="#linear-optimization" id="toc-linear-optimization" class="nav-link" data-scroll-target="#linear-optimization">linear-optimization</a></li>
  <li><a href="#maximize" id="toc-maximize" class="nav-link" data-scroll-target="#maximize">maximize</a></li>
  <li><a href="#maximizer" id="toc-maximizer" class="nav-link" data-scroll-target="#maximizer">maximizer</a></li>
  <li><a href="#minimize" id="toc-minimize" class="nav-link" data-scroll-target="#minimize">minimize</a></li>
  <li><a href="#minimizer" id="toc-minimizer" class="nav-link" data-scroll-target="#minimizer">minimizer</a></li>
  <li><a href="#scan-and-maximize" id="toc-scan-and-maximize" class="nav-link" data-scroll-target="#scan-and-maximize">scan-and-maximize</a></li>
  <li><a href="#scan-and-minimize" id="toc-scan-and-minimize" class="nav-link" data-scroll-target="#scan-and-minimize">scan-and-minimize</a></li>
  </ul></li>
  </ul></li>
  </ul>
</nav>
    </div>
<!-- main -->
<main class="content" id="quarto-document-content">

<header id="title-block-header" class="quarto-title-block default">
<div class="quarto-title">
<h1 class="title">Optimization</h1>
</div>



<div class="quarto-title-meta">

    
  
    
  </div>
  


</header>


<style></style>
<style>.printedClojure .sourceCode {
  background-color: transparent;
  border-style: none;
}
</style>
<style>.clay-limit-image-width .clay-image {max-width: 100%}
.clay-side-by-side .sourceCode {margin: 0}
.clay-side-by-side {margin: 1em 0}
</style>
<script src="optimization_files/md-default0.js" type="text/javascript"></script>
<script src="optimization_files/md-default1.js" type="text/javascript"></script>
<div class="sourceClojure">
<div class="sourceCode" id="cb1"><pre class="sourceCode clojure code-with-copy"><code class="sourceCode clojure"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a>(<span class="kw">ns</span> optimization</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a>  (<span class="at">:require</span> [fastmath.optimization <span class="at">:as</span> opt]</span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a>            [fastmath.dev.codox <span class="at">:as</span> codox]))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<section id="bayesian-optimization" class="level2">
<h2 class="anchored" data-anchor-id="bayesian-optimization">Bayesian optimization</h2>
</section>
<section id="reference" class="level2">
<h2 class="anchored" data-anchor-id="reference">Reference</h2>
<section id="fastmath.optimization" class="level3">
<h3 class="anchored" data-anchor-id="fastmath.optimization">fastmath.optimization</h3>
<p>Optimization.</p>
<p>Namespace provides various optimization methods.</p>
<ul>
<li>Brent (1d functions)</li>
<li>Bobyqa (2d+ functions)</li>
<li>Powell</li>
<li>Nelder-Mead</li>
<li>Multidirectional simplex</li>
<li>CMAES</li>
<li>Gradient</li>
<li>L-BFGS-B</li>
<li>Bayesian Optimization (see below)</li>
<li>Linear optimization</li>
</ul>
<p>All optimizers require bounds.</p>
<p>## Optimizers</p>
<p>To optimize functions call one of the following functions:</p>
<ul>
<li><a href="#LOS-minimize">minimize</a> or <a href="#LOS-maximize">maximize</a> - to perform actual optimization</li>
<li><a href="#LOS-scan-and-minimize">scan-and-minimize</a> or <a href="#LOS-scan-and-maximize">scan-and-maximize</a> - functions find initial point using brute force and then perform optimization paralelly for best initialization points. Brute force scan is done using jitter low discrepancy sequence generator.</li>
</ul>
<p>You can also create optimizer (function which performs optimization) by calling <a href="#LOS-minimizer">minimizer</a> or <a href="#LOS-maximizer">maximizer</a>. Optimizer accepts initial point.</p>
<p>All above accept:</p>
<ul>
<li>one of the optimization method, ie: <code>:brent</code>, <code>:bobyqa</code>, <code>:nelder-mead</code>, <code>:multidirectional-simplex</code>, <code>:cmaes</code>, <code>:gradient</code>, <code>:bfgs</code> and <code>:lbfgsb</code></li>
<li>function to optimize</li>
<li>parameters as a map</li>
</ul>
<p>For parameters meaning refer <a href="https://commons.apache.org/proper/commons-math/javadocs/api-3.6.1/index.html?org/apache/commons/math3/optim/package-summary.html">Optim package</a></p>
<p>### Common parameters</p>
<ul>
<li><code>:bounds</code> (obligatory) - search ranges for each dimensions as a seqence of [low high] pairs</li>
<li><code>:initial</code> - initial point other then mid of the bounds as vector</li>
<li><code>:max-evals</code> - maximum number of function evaluations</li>
<li><code>:max-iters</code> - maximum number of algorithm interations</li>
<li><code>:bounded?</code> - should optimizer force to keep search within bounds (some algorithms go outside desired ranges)</li>
<li><code>:stats?</code> - return number of iterations and evaluations along with result</li>
<li><code>:rel</code> and <code>:abs</code> - relative and absolute accepted errors</li>
</ul>
<p>For <code>scan-and-...</code> functions additionally you can provide:</p>
<ul>
<li><code>:N</code> - number of brute force iterations</li>
<li><code>:n</code> - fraction of N which are used as initial points to parallel optimization</li>
<li><code>:jitter</code> - jitter factor for sequence generator (for scanning domain)</li>
</ul>
<p>### Specific parameters</p>
<ul>
<li>BOBYQA - <code>:number-of-points</code>, <code>:initial-radius</code>, <code>:stopping-radius</code></li>
<li>Nelder-Mead - <code>:rho</code>, <code>:khi</code>, <code>:gamma</code>, <code>:sigma</code>, <code>:side-length</code></li>
<li>Multidirectional simples - <code>:khi</code>, <code>:gamma</code>, <code>:side-length</code></li>
<li>CMAES - <code>:check-feasable-count</code>, <code>:diagonal-only</code>, <code>:stop-fitness</code>, <code>:active-cma?</code>, <code>:population-size</code></li>
<li>Gradient - <code>:bracketing-range</code>, <code>:formula</code> (<code>:polak-ribiere</code> or <code>:fletcher-reeves</code>), <code>:gradient-h</code> (finite differentiation step, default: <code>0.01</code>)</li>
</ul>
<p>## Bayesian Optimization</p>
<p>Bayesian optimizer can be used for optimizing expensive to evaluate black box functions. Refer this <a href="http://krasserm.github.io/2018/03/21/bayesian-optimization/">article</a> or this <a href="https://nextjournal.com/a/LKqpdDdxiggRyHhqDG5FH?token=Ss1Qq3MzHWN8ZyEt9UC1ZZ">article</a></p>
<p>## Linear optimization</p>
<span id="#LOS-bayesian-optimization"></span>
<section id="bayesian-optimization-1" class="level4">
<h4 class="anchored" data-anchor-id="bayesian-optimization-1">bayesian-optimization</h4>
<ul>
<li><code>(bayesian-optimization f {:keys [warm-up init-points bounds utility-function-type utility-param kernel kscale jitter noise optimizer optimizer-params normalize?], :or {utility-function-type :ucb, init-points 3, jitter 0.25, noise 1.0E-8, utility-param (if (#{:ei :poi} utility-function-type) 0.001 2.576), warm-up (* (count bounds) 1000), normalize? true, kernel :matern-52, kscale 1.0}})</code></li>
</ul>
<p>Bayesian optimizer</p>
<p>Parameters are:</p>
<ul>
<li><code>:warm-up</code> - number of brute force iterations to find maximum of utility function</li>
<li><code>:init-points</code> - number of initial evaluation before bayesian optimization starts. Points are selected using jittered low discrepancy sequence generator (see: <a href="#LOS-jittered-sequence-generator">jittered-sequence-generator</a></li>
<li><code>:bounds</code> - bounds for each dimension</li>
<li><code>:utility-function-type</code> - one of <code>:ei</code>, <code>:poi</code> or <code>:ucb</code></li>
<li><code>:utility-param</code> - parameter for utility function (kappa for <code>ucb</code> and xi for <code>ei</code> and <code>poi</code>)</li>
<li><code>:kernel</code> - kernel, default <code>:matern-52</code>, see <a href="#LOS-fastmath.kernel">fastmath.kernel</a></li>
<li><code>:kscale</code> - scaling factor for kernel</li>
<li><code>:jitter</code> - jitter factor for sequence generator (used to find initial points)</li>
<li><code>:noise</code> - noise (lambda) factor for gaussian process</li>
<li><code>:optimizer</code> - name of optimizer (used to optimized utility function)</li>
<li><code>:optimizer-params</code> - optional parameters for optimizer</li>
<li><code>:normalize?</code> - normalize data in gaussian process?</li>
</ul>
<p>Returns lazy sequence with consecutive executions. Each step consist:</p>
<ul>
<li><code>:x</code> - maximum <code>x</code></li>
<li><code>:y</code> - value</li>
<li><code>:xs</code> - list of all visited x’s</li>
<li><code>:ys</code> - list of values for every visited x</li>
<li><code>:gp</code> - current gaussian process regression instance</li>
<li><code>:util-fn</code> - current utility function</li>
<li><code>:util-best</code> - best x in utility function</li>
</ul>
<div style="text-align: right"><small><a href="https://github.com/generateme/fastmath/tree/3.x/src/fastmath/optimization.clj#L459">source</a></small><hr style="margin: 0"></div>
<span id="#LOS-linear-optimization"></span>
</section>
<section id="linear-optimization" class="level4">
<h4 class="anchored" data-anchor-id="linear-optimization">linear-optimization</h4>
<ul>
<li><code>(linear-optimization target constraints)</code></li>
<li><code>(linear-optimization target constraints {:keys [goal epsilon max-ulps cut-off rule non-negative? max-iter stats?], :or {goal :minimize, epsilon 1.0E-6, max-ulps 10, cut-off 1.0E-10, rule :dantzig, non-negative? false, max-iter Integer/MAX_VALUE}})</code></li>
</ul>
<p>Solves a linear problem.</p>
<p>Target is defined as a vector of coefficients and constant as the last value: <code>[a1 a2 a3 ... c]</code> means <code>f(x1,x2,x3) = a1*x1 + a2*x2 + a3*x3 + ... +  c</code></p>
<p>Constraints are defined as a sequence of one of the following triplets:</p>
<ul>
<li><code>[a1 a2 a3 ...] R n</code> - which means <code>a1*x1+a2*x2+a3*x3+... R n</code></li>
<li><code>[a1 a2 a3 ... ca] R [b1 b2 b3 ... cb]</code> - which means <code>a1*x1+a2*x2+a3*x3+...+ca R b1*x1+b2*x2+b3*x3+...+cb</code></li>
</ul>
<p><code>R</code> is a relationship and can be one of <code>&lt;=</code>, <code>&gt;=</code> or <code>=</code> as symbol or keyword. Also <code>:leq</code>, <code>:geq</code> and <code>:eq</code> are valid.</p>
<p>Function returns pair of optimal point and function value. If <code>stat?</code> option is set to true, returns also information about number of iterations.</p>
<p>Possible options:</p>
<ul>
<li><code>:goal</code> - <code>:minimize</code> (default) or <code>:maximize</code></li>
<li><code>:rule</code> - pivot selection rule, <code>:dantzig</code> (default) or <code>:bland</code></li>
<li><code>:max-iter</code> - maximum number of iterations, maximum integer by default</li>
<li><code>:non-negative?</code> - allow non-negative variables only, default: <code>false</code></li>
<li><code>:epsilon</code> - convergence value, default: <code>1.0e-6</code>:</li>
<li><code>:max-ulps</code> - floating point comparisons, default: <code>10</code> ulp</li>
<li><code>:cut-off</code> - pivot elements smaller than cut-off are treated as zero, default: <code>1.0e-10</code></li>
</ul>
<div class="sourceCode" id="cb2"><pre class="sourceCode clojure code-with-copy"><code class="sourceCode clojure"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a>(linear-optimization [-<span class="dv">1</span> <span class="dv">4</span> <span class="dv">0</span>] [[-<span class="dv">3</span> <span class="dv">1</span>] :&lt;= <span class="dv">6</span></span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a>                               [-<span class="dv">1</span> -<span class="dv">2</span>] :&gt;= -<span class="dv">4</span></span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a>                               [<span class="dv">0</span> <span class="dv">1</span>] :&gt;= -<span class="dv">3</span>])</span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a><span class="co">;; =&gt; [(9.999999999999995 -3.0) -21.999999999999993]</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div style="text-align: right"><small><a href="https://github.com/generateme/fastmath/tree/3.x/src/fastmath/optimization.clj#L529">source</a></small><hr style="margin: 0"></div>
<span id="#LOS-maximize"></span>
</section>
<section id="maximize" class="level4">
<h4 class="anchored" data-anchor-id="maximize">maximize</h4>
<ul>
<li><code>(maximize method f config)</code></li>
</ul>
<p>Maximize given function.</p>
<p>Parameters: optimization method, function and configuration.</p>
<div style="text-align: right"><small><a href="https://github.com/generateme/fastmath/tree/3.x/src/fastmath/optimization.clj#L338">source</a></small><hr style="margin: 0"></div>
<span id="#LOS-maximizer"></span>
</section>
<section id="maximizer" class="level4">
<h4 class="anchored" data-anchor-id="maximizer">maximizer</h4>
<ul>
<li><code>(maximizer method f config)</code></li>
</ul>
<p>Create optimizer which maximizes function.</p>
<p>Returns function which performs optimization for optionally given initial point.</p>
<div style="text-align: right"><small><a href="https://github.com/generateme/fastmath/tree/3.x/src/fastmath/optimization.clj#L323">source</a></small><hr style="margin: 0"></div>
<span id="#LOS-minimize"></span>
</section>
<section id="minimize" class="level4">
<h4 class="anchored" data-anchor-id="minimize">minimize</h4>
<ul>
<li><code>(minimize method f config)</code></li>
</ul>
<p>Minimize given function.</p>
<p>Parameters: optimization method, function and configuration.</p>
<div style="text-align: right"><small><a href="https://github.com/generateme/fastmath/tree/3.x/src/fastmath/optimization.clj#L332">source</a></small><hr style="margin: 0"></div>
<span id="#LOS-minimizer"></span>
</section>
<section id="minimizer" class="level4">
<h4 class="anchored" data-anchor-id="minimizer">minimizer</h4>
<ul>
<li><code>(minimizer method f config)</code></li>
</ul>
<p>Create optimizer which minimizes function.</p>
<p>Returns function which performs optimization for optionally given initial point.</p>
<div style="text-align: right"><small><a href="https://github.com/generateme/fastmath/tree/3.x/src/fastmath/optimization.clj#L317">source</a></small><hr style="margin: 0"></div>
<span id="#LOS-scan-and-maximize"></span>
</section>
<section id="scan-and-maximize" class="level4">
<h4 class="anchored" data-anchor-id="scan-and-maximize">scan-and-maximize</h4>
<div style="text-align: right"><small><a href="https://github.com/generateme/fastmath/tree/3.x/src/fastmath/optimization.clj#L393">source</a></small><hr style="margin: 0"></div>
<span id="#LOS-scan-and-minimize"></span>
</section>
<section id="scan-and-minimize" class="level4">
<h4 class="anchored" data-anchor-id="scan-and-minimize">scan-and-minimize</h4>
<div style="text-align: right"><small><a href="https://github.com/generateme/fastmath/tree/3.x/src/fastmath/optimization.clj#L392">source</a></small><hr style="margin: 0"></div>
<div style="background-color:grey;height:2px;width:100%;"></div>
<div><pre><small><small>source: <a href="https://github.com/generateme/fastmath//blob/master/clay/optimization.clj">clay/optimization.clj</a></small></small></pre></div>


</section>
</section>
</section>

</main> <!-- /main -->
<script id="quarto-html-after-body" type="application/javascript">
window.document.addEventListener("DOMContentLoaded", function (event) {
  const toggleBodyColorMode = (bsSheetEl) => {
    const mode = bsSheetEl.getAttribute("data-mode");
    const bodyEl = window.document.querySelector("body");
    if (mode === "dark") {
      bodyEl.classList.add("quarto-dark");
      bodyEl.classList.remove("quarto-light");
    } else {
      bodyEl.classList.add("quarto-light");
      bodyEl.classList.remove("quarto-dark");
    }
  }
  const toggleBodyColorPrimary = () => {
    const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
    if (bsSheetEl) {
      toggleBodyColorMode(bsSheetEl);
    }
  }
  toggleBodyColorPrimary();  
  const icon = "";
  const anchorJS = new window.AnchorJS();
  anchorJS.options = {
    placement: 'right',
    icon: icon
  };
  anchorJS.add('.anchored');
  const isCodeAnnotation = (el) => {
    for (const clz of el.classList) {
      if (clz.startsWith('code-annotation-')) {                     
        return true;
      }
    }
    return false;
  }
  const clipboard = new window.ClipboardJS('.code-copy-button', {
    text: function(trigger) {
      const codeEl = trigger.previousElementSibling.cloneNode(true);
      for (const childEl of codeEl.children) {
        if (isCodeAnnotation(childEl)) {
          childEl.remove();
        }
      }
      return codeEl.innerText;
    }
  });
  clipboard.on('success', function(e) {
    // button target
    const button = e.trigger;
    // don't keep focus
    button.blur();
    // flash "checked"
    button.classList.add('code-copy-button-checked');
    var currentTitle = button.getAttribute("title");
    button.setAttribute("title", "Copied!");
    let tooltip;
    if (window.bootstrap) {
      button.setAttribute("data-bs-toggle", "tooltip");
      button.setAttribute("data-bs-placement", "left");
      button.setAttribute("data-bs-title", "Copied!");
      tooltip = new bootstrap.Tooltip(button, 
        { trigger: "manual", 
          customClass: "code-copy-button-tooltip",
          offset: [0, -8]});
      tooltip.show();    
    }
    setTimeout(function() {
      if (tooltip) {
        tooltip.hide();
        button.removeAttribute("data-bs-title");
        button.removeAttribute("data-bs-toggle");
        button.removeAttribute("data-bs-placement");
      }
      button.setAttribute("title", currentTitle);
      button.classList.remove('code-copy-button-checked');
    }, 1000);
    // clear code selection
    e.clearSelection();
  });
  function tippyHover(el, contentFn, onTriggerFn, onUntriggerFn) {
    const config = {
      allowHTML: true,
      maxWidth: 500,
      delay: 100,
      arrow: false,
      appendTo: function(el) {
          return el.parentElement;
      },
      interactive: true,
      interactiveBorder: 10,
      theme: 'quarto',
      placement: 'bottom-start',
    };
    if (contentFn) {
      config.content = contentFn;
    }
    if (onTriggerFn) {
      config.onTrigger = onTriggerFn;
    }
    if (onUntriggerFn) {
      config.onUntrigger = onUntriggerFn;
    }
    window.tippy(el, config); 
  }
  const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
  for (var i=0; i<noterefs.length; i++) {
    const ref = noterefs[i];
    tippyHover(ref, function() {
      // use id or data attribute instead here
      let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
      try { href = new URL(href).hash; } catch {}
      const id = href.replace(/^#\/?/, "");
      const note = window.document.getElementById(id);
      return note.innerHTML;
    });
  }
  const xrefs = window.document.querySelectorAll('a.quarto-xref');
  const processXRef = (id, note) => {
    // Strip column container classes
    const stripColumnClz = (el) => {
      el.classList.remove("page-full", "page-columns");
      if (el.children) {
        for (const child of el.children) {
          stripColumnClz(child);
        }
      }
    }
    stripColumnClz(note)
    if (id === null || id.startsWith('sec-')) {
      // Special case sections, only their first couple elements
      const container = document.createElement("div");
      if (note.children && note.children.length > 2) {
        container.appendChild(note.children[0].cloneNode(true));
        for (let i = 1; i < note.children.length; i++) {
          const child = note.children[i];
          if (child.tagName === "P" && child.innerText === "") {
            continue;
          } else {
            container.appendChild(child.cloneNode(true));
            break;
          }
        }
        if (window.Quarto?.typesetMath) {
          window.Quarto.typesetMath(container);
        }
        return container.innerHTML
      } else {
        if (window.Quarto?.typesetMath) {
          window.Quarto.typesetMath(note);
        }
        return note.innerHTML;
      }
    } else {
      // Remove any anchor links if they are present
      const anchorLink = note.querySelector('a.anchorjs-link');
      if (anchorLink) {
        anchorLink.remove();
      }
      if (window.Quarto?.typesetMath) {
        window.Quarto.typesetMath(note);
      }
      // TODO in 1.5, we should make sure this works without a callout special case
      if (note.classList.contains("callout")) {
        return note.outerHTML;
      } else {
        return note.innerHTML;
      }
    }
  }
  for (var i=0; i<xrefs.length; i++) {
    const xref = xrefs[i];
    tippyHover(xref, undefined, function(instance) {
      instance.disable();
      let url = xref.getAttribute('href');
      let hash = undefined; 
      if (url.startsWith('#')) {
        hash = url;
      } else {
        try { hash = new URL(url).hash; } catch {}
      }
      if (hash) {
        const id = hash.replace(/^#\/?/, "");
        const note = window.document.getElementById(id);
        if (note !== null) {
          try {
            const html = processXRef(id, note.cloneNode(true));
            instance.setContent(html);
          } finally {
            instance.enable();
            instance.show();
          }
        } else {
          // See if we can fetch this
          fetch(url.split('#')[0])
          .then(res => res.text())
          .then(html => {
            const parser = new DOMParser();
            const htmlDoc = parser.parseFromString(html, "text/html");
            const note = htmlDoc.getElementById(id);
            if (note !== null) {
              const html = processXRef(id, note);
              instance.setContent(html);
            } 
          }).finally(() => {
            instance.enable();
            instance.show();
          });
        }
      } else {
        // See if we can fetch a full url (with no hash to target)
        // This is a special case and we should probably do some content thinning / targeting
        fetch(url)
        .then(res => res.text())
        .then(html => {
          const parser = new DOMParser();
          const htmlDoc = parser.parseFromString(html, "text/html");
          const note = htmlDoc.querySelector('main.content');
          if (note !== null) {
            // This should only happen for chapter cross references
            // (since there is no id in the URL)
            // remove the first header
            if (note.children.length > 0 && note.children[0].tagName === "HEADER") {
              note.children[0].remove();
            }
            const html = processXRef(null, note);
            instance.setContent(html);
          } 
        }).finally(() => {
          instance.enable();
          instance.show();
        });
      }
    }, function(instance) {
    });
  }
      let selectedAnnoteEl;
      const selectorForAnnotation = ( cell, annotation) => {
        let cellAttr = 'data-code-cell="' + cell + '"';
        let lineAttr = 'data-code-annotation="' +  annotation + '"';
        const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
        return selector;
      }
      const selectCodeLines = (annoteEl) => {
        const doc = window.document;
        const targetCell = annoteEl.getAttribute("data-target-cell");
        const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
        const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
        const lines = annoteSpan.getAttribute("data-code-lines").split(",");
        const lineIds = lines.map((line) => {
          return targetCell + "-" + line;
        })
        let top = null;
        let height = null;
        let parent = null;
        if (lineIds.length > 0) {
            //compute the position of the single el (top and bottom and make a div)
            const el = window.document.getElementById(lineIds[0]);
            top = el.offsetTop;
            height = el.offsetHeight;
            parent = el.parentElement.parentElement;
          if (lineIds.length > 1) {
            const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
            const bottom = lastEl.offsetTop + lastEl.offsetHeight;
            height = bottom - top;
          }
          if (top !== null && height !== null && parent !== null) {
            // cook up a div (if necessary) and position it 
            let div = window.document.getElementById("code-annotation-line-highlight");
            if (div === null) {
              div = window.document.createElement("div");
              div.setAttribute("id", "code-annotation-line-highlight");
              div.style.position = 'absolute';
              parent.appendChild(div);
            }
            div.style.top = top - 2 + "px";
            div.style.height = height + 4 + "px";
            div.style.left = 0;
            let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
            if (gutterDiv === null) {
              gutterDiv = window.document.createElement("div");
              gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
              gutterDiv.style.position = 'absolute';
              const codeCell = window.document.getElementById(targetCell);
              const gutter = codeCell.querySelector('.code-annotation-gutter');
              gutter.appendChild(gutterDiv);
            }
            gutterDiv.style.top = top - 2 + "px";
            gutterDiv.style.height = height + 4 + "px";
          }
          selectedAnnoteEl = annoteEl;
        }
      };
      const unselectCodeLines = () => {
        const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
        elementsIds.forEach((elId) => {
          const div = window.document.getElementById(elId);
          if (div) {
            div.remove();
          }
        });
        selectedAnnoteEl = undefined;
      };
        // Handle positioning of the toggle
    window.addEventListener(
      "resize",
      throttle(() => {
        elRect = undefined;
        if (selectedAnnoteEl) {
          selectCodeLines(selectedAnnoteEl);
        }
      }, 10)
    );
    function throttle(fn, ms) {
    let throttle = false;
    let timer;
      return (...args) => {
        if(!throttle) { // first call gets through
            fn.apply(this, args);
            throttle = true;
        } else { // all the others get throttled
            if(timer) clearTimeout(timer); // cancel #2
            timer = setTimeout(() => {
              fn.apply(this, args);
              timer = throttle = false;
            }, ms);
        }
      };
    }
      // Attach click handler to the DT
      const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
      for (const annoteDlNode of annoteDls) {
        annoteDlNode.addEventListener('click', (event) => {
          const clickedEl = event.target;
          if (clickedEl !== selectedAnnoteEl) {
            unselectCodeLines();
            const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
            if (activeEl) {
              activeEl.classList.remove('code-annotation-active');
            }
            selectCodeLines(clickedEl);
            clickedEl.classList.add('code-annotation-active');
          } else {
            // Unselect the line
            unselectCodeLines();
            clickedEl.classList.remove('code-annotation-active');
          }
        });
      }
  const findCites = (el) => {
    const parentEl = el.parentElement;
    if (parentEl) {
      const cites = parentEl.dataset.cites;
      if (cites) {
        return {
          el,
          cites: cites.split(' ')
        };
      } else {
        return findCites(el.parentElement)
      }
    } else {
      return undefined;
    }
  };
  var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
  for (var i=0; i<bibliorefs.length; i++) {
    const ref = bibliorefs[i];
    const citeInfo = findCites(ref);
    if (citeInfo) {
      tippyHover(citeInfo.el, function() {
        var popup = window.document.createElement('div');
        citeInfo.cites.forEach(function(cite) {
          var citeDiv = window.document.createElement('div');
          citeDiv.classList.add('hanging-indent');
          citeDiv.classList.add('csl-entry');
          var biblioDiv = window.document.getElementById('ref-' + cite);
          if (biblioDiv) {
            citeDiv.innerHTML = biblioDiv.innerHTML;
          }
          popup.appendChild(citeDiv);
        });
        return popup.innerHTML;
      });
    }
  }
});
</script>
<nav class="page-navigation">
  <div class="nav-page nav-page-previous">
      <a href="./interpolation.html" class="pagination-link" aria-label="Interpolation">
        <i class="bi bi-arrow-left-short"></i> <span class="nav-page-text">Interpolation</span>
      </a>          
  </div>
  <div class="nav-page nav-page-next">
      <a href="./transform.html" class="pagination-link" aria-label="Transforms">
        <span class="nav-page-text">Transforms</span> <i class="bi bi-arrow-right-short"></i>
      </a>
  </div>
</nav>
</div> <!-- /content -->




</body></html>